package com.student.education.controller;

import com.student.education.common.CommonResult;
import com.student.education.entity.CheckWorkType;
import com.student.education.service.CheckWorkTypeService;
import com.student.education.to.CheckWorkTypeQueryTo;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 考勤类型表(CheckWorkType)表控制层
 *
 * @author makejava
 * @since 2021-10-09 23:40:03
 */
@RestController
@RequestMapping("/checkWorkType")
public class CheckWorkTypeController {
    /**
     * 服务对象
     */
    @Resource
    private CheckWorkTypeService checkWorkTypeService;



    /**
     * 查询所有的考勤类型
     *
     * @param
     * @return 单条数据
     */
    @GetMapping("/queryAll")
    public CommonResult<List<CheckWorkTypeQueryTo>> queryAll() {
        return CommonResult.success(checkWorkTypeService.queryAll());
    }


    /**
     * 新增数据
     *
     * @param checkWorkType 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody CheckWorkType checkWorkType) {
        int insert = checkWorkTypeService.insert(checkWorkType);
        if (insert>0){
            return CommonResult.success("新增成功");
        }
        return CommonResult.error("新增失败");
    }

    /**
     * 修改数据
     *
     * @param
     * @return 编辑结果
     */
    @GetMapping("/update")
    public CommonResult<String> update(Integer id,String name) {
        int insert = checkWorkTypeService.update(id,name);
        if (insert>0){
            return CommonResult.success("修改成功");
        }
        return CommonResult.error("修改失败");
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @GetMapping("/delete")
    public CommonResult<String> deleteById(Integer id) {
        if (checkWorkTypeService.deleteById(id)){
            return CommonResult.success("删除成功");
        }
        return CommonResult.error("删除失败");
    }

}

